package com.cuit.zuke.hotel.controller;


import com.cuit.zuke.hotel.model.hotel.HotelRoom;
import com.cuit.zuke.hotel.service.HotelBookService;
import com.cuit.zuke.hotel.service.HotelRoomService;
import com.cuit.zuke.hotel.service.HotelService;
import com.cuit.zuke.hotel.model.hotel.Hotel;
import com.cuit.zuke.common.util.Result;
import com.cuit.zuke.hotel.vo.hotel.HotelQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

import java.util.List;

@Api(tags = "酒店管理接口")
@RestController
@RequestMapping("/hotel/hotel")
public class HotelController {

    @Autowired
    private HotelService hotelService;

    /**
     * 获取分页列表
     * @param page 当前页码
     * @param limit 每页记录数
     * @param hotelQueryVo 查询对象
     * @return 符合条件的酒店数据
     */
    @ApiOperation(value = "获取分页列表")
    @PostMapping("{page}/{limit}")
    public Result index(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,

            @ApiParam(name = "hotelQueryVo", value = "查询对象", required = false)
            @RequestBody
                    HotelQueryVo hotelQueryVo) {
        return Result.ok().setData(hotelService.selectPage(page, limit, hotelQueryVo));
    }

    /**
     * 更新上线状态
     * @param id 酒店id
     * @param status 状态（0：未上线 1：已上线）
     * @return 1 or 0
     */
    @ApiOperation(value = "更新上线状态")
    @GetMapping("updateStatus/{id}/{status}")
    public Result lock(
            @ApiParam(name = "id", value = "酒店id", required = true)
            @PathVariable("id") String id,
            @ApiParam(name = "status", value = "状态（0：未上线 1：已上线）", required = true)
            @PathVariable("status") Integer status) {
        hotelService.updateStatus(id, status);
        return Result.ok();
    }

    /**
     * 获取酒店详情
     * @param id 酒店编号
     * @return 酒店数据
     */
    @ApiOperation(value = "获取酒店详情")
    @GetMapping("show/{id}")
    public Result show(
            @ApiParam(name = "id", value = "酒店编号", required = true)
            @PathVariable String id) {
        return Result.ok().setData(hotelService.item(id));
    }

    /**
     * 增加酒店详情
     * @param hotel hotel实体
     * @return 1 or 0
     */
    @ApiOperation(value = "增加酒店详情")
    @PostMapping("add")
    public Result add(@RequestBody Hotel hotel) {
        hotelService.save(hotel);
        return Result.ok();
    }

    @GetMapping("getHotelAndRoom/{zkcode}/{roomcode}")
    public Map<String, Object> getHotelAndRoom(@PathVariable("zkcode") String zkcode, @PathVariable("roomcode") String roomcode) {
        Map<String, Object> resultMap = hotelService.getHotelAndRoom(zkcode,roomcode);
        return resultMap;
    }

}

